var currentwindow;
var counts = "";

mui.plusReady(function() {
	$("#all").html("");
	$("#all").html(
		'<a style="font-size:100px; color:rgba(242,125,72,1.00); display:block; text-align:center;" class="mui-icon mui-icon-search"></a><a class="mui-title" style="color:rgba(128,128,128,1.00); position: initial; margin: 0 auto; height:' +
		(window.screen.height - 200) + 'px">No data available at the moment</a>');
	if (window.plus && plus.nativeUI) {
		plus.nativeUI.closeWaiting();
	}

})


var UserNO = localStorage.getItem("UserNO");
//alert(UserNO);
function showinfo(e) {
	e.preventDefault();
	change2(1);
}

function openPosition(TradeOrderNO, OutWarehouse, OutWarehouseID, InWarehouse) {
	console.log(UserNO)
	mui.openWindow({
		url: 'WMSWorkOrder_GetMatial.html',
		action: UserNO,
		extras: {
			TradeOrderNO: TradeOrderNO,
			OutWarehouse: OutWarehouse,
			OutWarehouseID: OutWarehouseID,
			InWarehouse: InWarehouse
		}
	});
}




function change2(e) {
	pageno = e;
	var pageall;
	//$("#all").html("");//全部清空
	var html = "";
	var TradeOrderNO = $("#TradeNO").val();
	var CreateTime = $("#Creatime").val();
	xccFormPostAsync("api/PDA/GetTradeInfo", {
		PageIndex: e,
		PageSize: 10,
		TradeOrderNO: TradeOrderNO,
		CreateTime: CreateTime,
		TradeType: 5,
		RState: 0
	}, function(data) {
		pageall = Math.ceil(parseInt(data.Items.length) / 10) //向上取整    parseInt:转换为INT类型
		if (data.Items.length != null && data.Items.length > 0) {
			$("#all").html(""); ////全部清空
			for (var i = 0; i < data.Items.length; i++) {
				$("#all").append(`<li class="mui-table-view-cell" onclick="openPosition(
					'${data.Items[i].TradeOrderNO}','${data.Items[i].WarehouseName}','${data.Items[i].FromWarehouseID}',
					'${data.Items[i].ToWarehouseName}')">
					<div class="list-title">Order ${data.Items[i].TradeOrderNO}</div>
					<div class="list-detail">OutWarehouse: ${data.Items[i].WarehouseName}</div>
					<div class="list-detail">ToWarehouse: ${data.Items[i].ToWarehouseName}</div>
					<div class="list-detail">Date: ${data.Items[i].CreateTime}</div></li>`)

				if (e < 1) {
					e = 1;
					pageno = 1; //就等于第1页 ， 当前页为1
				}
				if (pageall === 0) pageall = 1; // 确保最小为 1
				if (e > pageall) { //如果输入页大于最大页
					e = pageall;
					pageno = pageall; //输入页和当前页都=最大页
				}
				var pageContent = "";
				pageContent += 'page<span id=\"a2\">' + pageno + '</span>/';
				pageContent += '<span id="a1">' + pageall + '</span>';
				/*pageContent +='<span id="a3" >'+ye+'</span>';*/
				if (e > 1) { //页数大于1不能上一页
					pageContent += '<a href="#" onClick="change2(--pageno)" >previous page</a>';
				}
				if (e < pageall) { //页数小于不能上一页
					pageContent += '<a href="#" onClick="change2(++pageno)">next page</a>';
				}
				if (pageno <= pageall) {
					$("#page").html(pageContent);
				}

			}
			plus.nativeUI.closeWaiting();
		} else {
			$("#all").html("");
			$("#all").html(
				'<a style="font-size:100px; color:rgba(242,125,72,1.00); display:block; text-align:center;" class="mui-icon mui-icon-search"></a><a class="mui-title" style="color:rgba(128,128,128,1.00); position: initial; margin: 0 auto; height:' +
				(window.screen.height - 400) + 'px">No data available at the moment</a>');
			plus.nativeUI.closeWaiting();
		}
	}, function(errr) {

		console.error("查询出错:", errr);
		plus.nativeUI.closeWaiting();
	})
}